﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Bitcoin.Common;

namespace Bitcoin.Test.Utility
{
    class ClockResetScope : IDisposable, IClock
    {
        private DateTimeOffset fakeTime;
        private IClock originalClock;

        public ClockResetScope(DateTimeOffset fakeTime)
        {
            this.fakeTime = fakeTime;
            originalClock = Clock.Current;
            Clock.Current = this;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                Clock.Current = originalClock;
            }
        }

        public DateTimeOffset UtcNow
        {
            get { return fakeTime; }
            set { fakeTime = value; }
        }
    }
}
